package com.gitee.wsl.common.draw

import android.graphics.Canvas

interface AnimatorAble{

    fun setInvalidateHander(invalidate:()->Unit)

    fun play(loop:Boolean = true)

    fun pause()

    fun setDuration(duration: Int)

}

interface AnimatorDrawItem:DrawerItem,AnimatorAble{

    var invalidate:(()->Unit)?

    fun recycler()

}

 open class AnimatorDrawable: AbstractDrawable() ,AnimatorDrawItem{

    var autoStartAble:Boolean = true

    private var animatorDrawItem:AnimatorDrawItem?=null

    fun setAnimatorDrawItem(drawItem:AnimatorDrawItem){
        animatorDrawItem?.recycler()
        animatorDrawItem=drawItem.apply {
            setInvalidateHander {
                drawItem.invalidate?.invoke()
             }
            //onSizeChanged(this@AnimatorDrawView.width,this@AnimatorDrawView.height,0,0)
        }
        if(autoStartAble)
            animatorDrawItem?.play()
    }

     override fun recycler(){
         pause()
         invalidate=null
     }

     override fun setInvalidateHander(invalidate: () -> Unit) {
         this.invalidate=invalidate
     }

     override fun setDuration(duration: Int) {
     }

     override fun draw(canvas: Canvas) {
         TODO("Not yet implemented")
     }

     override fun play(loop: Boolean) {
         TODO("Not yet implemented")
     }

     override fun pause() {
         TODO("Not yet implemented")
     }

     override var invalidate: (() -> Unit)?=null

 }

open class AnimatorTouchAbleDrawable<T>:AnimatorDrawable(),TouchDrawerItem<T>{

    override var touchListener: TouchListener<T>?=null


}